#define BOOT_DIR "/dualua"
#define BOOT_FILE "libs.lua"
#define BOOT_FULLPATH BOOT_DIR "/" BOOT_FILE

#include <stdio.h>
#include <stdlib.h>

#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>

#include <MessageQueue.h>
#include <802.11.h>
#include <lobby.h> 

#include <fat.h>

#include <dswifi9.h>
#include <netinet/in.h>

#include "dualualibs/efs_lib.h"
#include "dualualibs/dualualibs.h"

int main()
{
	consoleDemoInit();
	
	// Nifi initialization
	/*IPC_SetChannelCallback(0, &LWIFI_IPC_Callback);
	if (!LOBBY_Init()) {
		ulDebug("Error Occured : Can't initialize NiFi correctly.");
		swiWaitForVBlank();
	}*/
	
	// Fat initialization
	fatInitDefault();
	
	// EFS initialization
	/*if(!EFS_Init(EFS_AND_FAT | EFS_DEFAULT_DEVICE, NULL)) {
		ulDebug("Error Occured : EFS Init Error.");
		swiWaitForVBlank();
	}*/
	
	struct lua_State *l = lua_open();
	if (!l) {
		printf("\n\n\tFailed to create a Lua state - Push A to Exit\n");
		swiWaitForVBlank();
	}
	
	luaL_openlibs(l);
	dualua_openlibs(l);
	
	if (luaL_loadfile(l, BOOT_FULLPATH)) {
		printf("Error Occured: Couldn't open %s\n", BOOT_FULLPATH);
		swiWaitForVBlank();
	}
	
	if(lua_pcall(l,0,0,0)) {
		printf(lua_tostring(l, -1));
		lua_pop(l, 1);
		swiWaitForVBlank();
	}
	
	lua_close(l);
	
	return 0;
	/*int i;
 
	consoleDemoInit();
 
	videoSetMode(MODE_FB0);
 
	vramSetBankA(VRAM_A_LCD);
 
	printf("Hello World!\n");
	printf("www.Drunkencoders.com");
 
	for(i = 0; i < 256 * 192; i++)
		VRAM_A[i] = RGB15(31,0,0);
 
	swiWaitForVBlank();
	
	return 0;*/
}
